package com.tledu.production.service.people.impl;

import com.tledu.production.mapper.people.DepartmentMapper;
import com.tledu.production.mapper.people.EmployeeMapper;
import com.tledu.production.model.people.Department;
import com.tledu.production.service.people.IDepartmentService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Antg
 * @date 2021/8/17  11:10
 */
@Service
@AllArgsConstructor
public class DepartmentService implements IDepartmentService {
    private DepartmentMapper departmentMapper;
    private EmployeeMapper employeeMapper;

    @Override
    public List<Department> findAll() {
        return departmentMapper.findAll();
    }

    @Override
    public List<Department> search(String type, String searchText) {
        return departmentMapper.search(type, searchText);
    }

    @Override
    public int add(Department department) {
        return departmentMapper.add(department);
    }

    @Override
    public int edit(Department department) {
        return departmentMapper.edit(department);
    }

    @Override
    public int batchDel(String[] ids) {
        //这里执行删除的时候会关联到员工表,将一个部门删掉后,该部门所有的员工就被删除了
        employeeMapper.batchDelByDepId(ids);
        //删除完了之后再删除部门
        return departmentMapper.batchDel(ids);
    }
}
